package com.wiscamp.ninechapters.problems.domain.models.problems.questions;

import com.wiscamp.ninechapters.problems.domain.models.exams.ScoringRule;
import com.wiscamp.ninechapters.problems.domain.models.problems.answers.Answer;
import com.wiscamp.ninechapters.problems.domain.models.types.ProblemType;
import com.wiscamp.ninechapters.problems.domain.models.types.QuestionType;
import com.wiscamp.ninechapters.problems.enums.Actions;
import cube.ddd.domain.Entity;
import lombok.Data;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;

/**
 * 问题
 * 需要在问题的questionHyperText中定义各类型答案的替换符
 */
@Data
public class Question implements Entity {
    /**
     * 问题编号
     */
    private long questionId;

    /**
     * 题编号
     */
    private long problemId = 0;

    private long problemTypeId = 0;

    /**
     * 题类型
     */
    private ProblemType problemType = null;

    private long questionTypeId = 0;

    /**
     * 问题类型
     */
    private QuestionType questionType = null;

    /**
     * 问题序号
     */
    private int questionIndex;

    /**
     * 问题超文本
     */
    private String questionHypertext;

    /**
     * 问题翻译
     */
    private String questionTranslation = "";

    /**
     * 问题难度
     */
    private int difficulty;

    /**
     * 问题解析列表
     */
    private Collection<Solution> solutions = new ArrayList<>();

    /**
     * 首选问题解析
     */
    private Solution preferredSolution = null;

    /**
     * 答题时间限制
     */
    private int timeLimit = 0;

    /**
     * 问题分数
     */
    private double questionScore = 0;

    /**
     * 需要高亮显示的文本
     */
    private String highlightText = "";

    /**
     * 是否需要解题步骤
     */
    protected boolean needSteps = false;

    protected boolean hasOptions = false;

    /**
     * 是否有多个答案
     */
    protected boolean hasMultipleAnswers = false;

    private ScoringRule scoringRule;


    public void setCurrentAnswer(Answer answer) {
        return;
    }

    public Answer getCurrentAnswer() {
        return null;
    }

    public void setCurrentAnswers(Collection<Answer> answers) {
        return;
    }

    public Collection<Answer> getCurrentAnswers() {
        return new ArrayList<>();
    }

    public void setCurrentOptions(Collection<Option> options) {
        return;
    }

    public Collection<Option> getCurrentOptions() {
        return new ArrayList<>();
    }

    public Solution getPreferredSolution() {
        if (Objects.nonNull(preferredSolution)) return preferredSolution;

        if (!solutions.isEmpty()) {
            return (Solution) solutions.toArray()[0];
        }
        return null;
    }

    // region entity methods
    public double getCurrentQuestionScore() {
        if (questionScore > 0)
            return getQuestionScore();

        return getCurrentAnswers().size();
    }

    // endregion




    private Actions action = Actions.NONE;
}
